package distributedbank.sensor;


/**
 * One Sensor for one BankBranch. Sensor receives HeatBeatMessage from
 * BankBranch regularly. Whenever it fails to receive the HBM within a time
 * threshold T, send a SuspectRequest to ORACLE (Failure Detect Service).
 * Afterwards, when it receives HBM again, it sends a SuspectRequest to ORACLE
 * again showing that suspect status has changed.
 * 
 * Thus, we need BankBranch sends HBM to this once every period of time. The interval is
 * not determined yet.
 * 
 * 
 */
public class Sensor {
	private int branchId;
	private boolean suspected;

	// HOW TO DEFINE T
	private int T = 1000;

	public Sensor(int branchId) {
		this.branchId = branchId;
		this.suspected = false;
	}

	public static void main(String[] args) {
		if (args.length != 1) {
			System.out
					.println("Error: You must specify the branch ID on the command-line.");
			System.exit(1);
		} else {
			int branchId = Integer.valueOf(args[0]);
			new Sensor(branchId).run();
		}
	}

	private void run() {
		// TODO Listen to HeartBeatMessage from bankbranch with id = branchId
		// If time interval exceeds T, send a SuspectRequest to ORACLE, change
		// suspected to true.
		// If suspected == true and receives HBM, send SuspectRequest to ORACLE,
		// change suspected to false.

	}
}
